package com.usefullc.user.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.common.user.OnlineUser;
import com.usefullc.common.user.OnlineUserManager;
import com.usefullc.system.controller.WebResultBuilder;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.service.component.ImgCodeComponent;
import com.usefullc.system.service.component.SmsComponent;
import com.usefullc.system.service.component.SystemConfigComponent;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.user.domain.Tenant;
import com.usefullc.user.domain.User;
import com.usefullc.user.query.TenantQuery;
import com.usefullc.user.query.UserQuery;
import com.usefullc.user.service.EmployeeService;
import com.usefullc.user.service.TenantService;
import com.usefullc.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Sampson
 * @date: 2022-03-19 12:02
 */
@RestController
@RequestMapping(path = "/user/anonymous/")
@Api(tags = "用户匿名访问模块")
public class UserAnonymousController {

    @Autowired
    private ImgCodeComponent imgCodeComponent;

    @Autowired
    private SmsComponent smsComponent;

    @Autowired
    private UserService userService;

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private SystemConfigComponent systemConfigComponent;

    @Autowired
    private TenantService tenantService;



    @ApiOperation(value = "用户所有列表", response = WebResult.class)
    @GetMapping(path = "/user/listAll", produces = "application/json")
    public WebResult listAll(UserQuery query) {
//        query.setType(UserTypeEnum.ADMIN.getCode());
//        OnlineUser loginUser = OnlineUserManager.getLoginUser();
//        query.setTenantId(loginUser.getTenantId());
        List<User> dataList = userService.findAll(query);
        return WebResultBuilder.successResult(dataList);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "租户所有列表", response = WebResult.class)
    @GetMapping(path = "tenant/listAll", produces = "application/json")
    public WebResult listAll(@UsefulValid(query = true) TenantQuery query) {
        List<Tenant> dataList = tenantService.findAll(query);
        return WebResultBuilder.successResult(dataList);
    }



    @ApiOperation(value = "用户详情", response = WebResult.class)
    @GetMapping(path = "detail", produces = "application/json")
    public WebResult detail(@ApiParam(value = "用户ID", required = true, example = "1") @Valid @RequestParam Long id) {
        User user = userService.findById(id);
        return WebResultBuilder.successResult(user);
    }






}
